import re
#little function that takes in a cvs revision string and returns the previous revision. Returns blank if the previous rev is non existant

def previous(rev):
	numbers = re.split('\.', rev)
		
	#special cases
	if rev == '1.1.1.1':
		return None
	if rev == '1.1':
		return None
	
	#if only 2 digits, first digit MUST be 1, and it can't be 1.1 as filtered above
	if len(numbers) == 2:

		return numbers[0] + '.' + str(int(numbers[1])-1)
	#4 or more digit rev
	else:
		#recurse on all but first two numbers
		return numbers[0] + '.' + numbers[1] + nprevious(numbers[2:])

def nprevious(numbers):

	if len(numbers) == 2:
		if numbers[1] == '1':
			return ''
		else:
			return '.' + numbers[0] + '.' + str(int(numbers[1])-1)
	else:
		#recurse on all but first two numbers
		return '.' + numbers[0] + '.' + numbers[1] + nprevious(numbers[2:])
